/*
 * @Author: your name
 * @Date: 2021-10-09 10:03:45
 * @LastEditTime: 2021-12-01 14:48:38
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \cpp11\template.cpp
 */
#include "iostream"
#include <vector>
#include "pattern/ringbuffer.hpp"
#include <tuple>
#include <math.h>

using namespace std;

std::tuple<int,std::string> ReturnMoreData(){
    return std::tuple<int,std::string> (1,"sss");
}

void clearBuffer(int *dat,int len){
    for(int i = 0;i < len;i++){
        dat[i] = 0;
    }
}

void TestRingBuffer(){
    int in[1024];
    int out[1024];

    for(int i = 0;i < 1024;i ++){
        in[i] = i;
    }
    RingBuffer<int> x(1024);
    
    for(int i = 0;i < 10;i++){
        std::cout<<std::endl<<"----------------------------------"<<"\r\n";
        int ran = rand()%1024;
        int ret = x.Add(in,ran);
        std::cout<<"add "<<ran<<"  x.Length():" <<  x.Length() << " "<<std::endl;
        for(uint32_t i = 0;i < x.Length();i++){
            std::cout<<x.At(i) <<" ";
        }
        std::cout<<"----------------------------------"<<"\r\n";

        int ran2 = rand()%1024;
        x.TakeBack(out,ran2);
        std::cout<<"take "<<ran2<<"  x.Length():" <<  x.Length() << " "<<std::endl;
        for(uint32_t i = 0;i < x.Length();i++){
            std::cout<<x.At(i) <<" ";
        }
        std::cout<<std::endl<<"----------------------------------"<<"\r\n";

    }

    // int ret = x.Add(in,512);
    // std::cout<<"add "<<ret<<"  x.Length():" <<  x.Length() << " "<<std::endl;
    // for(uint32_t i = 0;i < x.Length();i++){
    //     std::cout<<x.At(i) <<" ";
    // }
    // std::cout<<"\r\n clear x----------------------------------"<<std::endl;
    // x.SetEmpty();
    // std::cout<<"\r\n ----------------------------------"<<std::endl;
    // std::cout<<"add data :"<<std::endl;
    // for(uint32_t i = 0;i < 516;i++){
    //     std::cout<<in[i] <<" ";
    // }
    // ret = x.Add(in,516);
    // std::cout<<"after add "<<ret << " length: "<< x.Length()<<"\r\n"<<std::endl;
    // for(uint32_t i = 0;i < x.Length();i++){
    //     std::cout<<x.At(i) <<" ";
    // }
    // std::cout<<"\r\n----------------------------------"<<std::endl;
    // clearBuffer(in,1024);
    // ret = x.Add(in,20);
    // std::cout<<"add "<<ret<<"\r\n"<<std::endl;
    // for(uint32_t i = 0;i < x.Length();i++){
    //     std::cout<<x.At(i) <<" ";
    // }
    // std::cout<<"\r\n----------------------------------"<<std::endl;
    // clearBuffer(in,1024);

    // std::cout<<"before take x: "<< x.Length()<<std::endl;
    // for(uint32_t i = 0;i < x.Length();i++){
    //     std::cout<<x.At(i) <<" ";
    // }
    // std::cout<<"\r\n----------------------------------"<<std::endl;
    // ret = x.TakeBack(in,20);
    // std::cout<<"take "<<ret<<"\r\n"<<std::endl;
    // for(uint32_t i = 0;i < ret;i++){
    //     std::cout<<in[i] <<" ";
    // }
    // std::cout<<"\r\n----------------------------------"<<std::endl;
    // std::cout<<"after take x: "<<x.Length()<<"\r\n"<<std::endl; 
    // for(uint32_t i = 0;i < x.Length();i++){
    //     std::cout<<x.At(i) <<" ";
    // }
    // clearBuffer(in,1024);
    // std::cout<<"\r\n----------------------------------"<<std::endl;
    // ret = x.TakeBack(in,20);
    // std::cout<<"take "<<ret<<"\r\n"<<std::endl;
    // for(uint32_t i = 0;i < ret;i++){
    //     std::cout<<in[i] <<" ";
    // }
    // std::cout<<"\r\n----------------------------------"<<std::endl;
    // std::cout<<"after take x: "<<x.Length()<<"\r\n"<<std::endl; 
    // std::cout<<"----------------------------------"<<"\r\n";
    // for(int z = 0;z < x.Length();z++){
    //     std::cout<<x.At(z) <<" ";
    // }
    // clearBuffer(in,1024);
    // ret = x.TakeFront(in,496);
    // std::cout<<"\r\ntake from front "<<ret<<"\r\n"<<std::endl;
    // for(uint32_t i = 0;i < ret;i++){
    //     std::cout<<in[i] <<" ";
    // }
    // std::cout<<"\r\nafter take x: "<<x.Length()<<"\r\n"<<std::endl; 
    // std::cout<<"----------------------------------"<<"\r\n";
    // for(int z = 0;z < x.Length();z++){
    //     std::cout<<x.At(z) <<" ";
    // }
    fflush(stdout);
}

int main() {

    // auto x = ReturnMoreData();
    // std::cout<<"x first is "<<std::get<0>(x) << std::get<1>(x)<<std::endl;
    // std::cout<<"main"<<std::endl;
    TestRingBuffer();
}